const inBrowser = typeof window !== 'undefined'
const UA = String(inBrowser && window.navigator.userAgent.toLowerCase())

export const isBlank = (o: string): boolean => !o || o.trim() === ''

export const isNotBlank = (o: string): boolean => !isBlank(o)

export const isWechat = (): boolean => UA.includes('micromessenger') && !UA.includes('wxwork')

export const isWechatWork = (): boolean => UA.includes('micromessenger') && UA.includes('wxwork')

export const isAndroid = (): boolean => UA.includes('android')

export const isIos = (): boolean => /iphone|ipad|ipod|ios/.test(UA)

export const isMobile = (): boolean => isAndroid() || isIos()

export const isPc = (): boolean => {
  const items = ['android', 'iphone', 'windows phone', 'ipad', 'ipod']
  for (const item of items) {
    if (UA.includes(item)) {
      return false
    }
  }
  return true
}
